Option Explicit On Option Strict On Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents LstResults As System.Windows.Forms.ListBox Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents TxtWins As System.Windows.Forms.TextBox Friend WithEvents TxtLosses As System.Windows.Forms.TextBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents BtnPlay As System.Windows.Forms.Button Friend WithEvents BtnReset As System.Windows.Forms.Button Friend WithEvents BtnQuit As System.Windows.Forms.Button Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox Friend WithEvents PicDice1 As System.Windows.Forms.PictureBox Friend WithEvents BtnContinue As System.Windows.Forms.Button Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents TxtTotal As System.Windows.Forms.TextBox Friend WithEvents TxtPoint As System.Windows.Forms.TextBox Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents PicDice2 As System.Windows.Forms.PictureBox Private Sub InitializeComponent() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) Me.Label1 = New System.Windows.Forms.Label Me.BtnPlay = New System.Windows.Forms.Button Me.LstResults = New System.Windows.Forms.ListBox Me.Label2 = New System.Windows.Forms.Label Me.TxtWins = New System.Windows.Forms.TextBox Me.TxtLosses = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.BtnReset = New System.Windows.Forms.Button Me.BtnQuit = New System.Windows.Forms.Button Me.GroupBox1 = New System.Windows.Forms.GroupBox Me.PicDice1 = New System.Windows.Forms.PictureBox Me.PicDice2 = New System.Windows.Forms.PictureBox Me.BtnContinue = New System.Windows.Forms.Button Me.Label4 = New System.Windows.Forms.Label Me.TxtTotal = New System.Windows.Forms.TextBox Me.TxtPoint = New System.Windows.Forms.TextBox Me.Label5 = New System.Windows.Forms.Label Me.GroupBox1.SuspendLayout() Me.SuspendLayout() ' 'Label1 ' Me.Label1.AutoSize = True Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(221, 18) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(128, 49) Me.Label1.TabIndex = 0 Me.Label1.Text = "Craps" ' 'BtnPlay ' Me.BtnPlay.Location = New System.Drawing.Point(24, 80) Me.BtnPlay.Name = "BtnPlay" Me.BtnPlay.Size = New System.Drawing.Size(105, 28) Me.BtnPlay.TabIndex = 1 Me.BtnPlay.Text = "Play" ' 'LstResults ' Me.LstResults.ItemHeight = 16 Me.LstResults.Location = New System.Drawing.Point(352, 80) Me.LstResults.Name = "LstResults" Me.LstResults.Size = New System.Drawing.Size(249, 340) Me.LstResults.TabIndex = 2 ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(24, 40) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(57, 18) Me.Label2.TabIndex = 3 Me.Label2.Text = "Wins" ' 'TxtWins ' Me.TxtWins.Location = New System.Drawing.Point(112, 40) Me.TxtWins.Name = "TxtWins" Me.TxtWins.ReadOnly = True Me.TxtWins.Size = New System.Drawing.Size(120, 22) Me.TxtWins.TabIndex = 4 Me.TxtWins.Text = "0" ' 'TxtLosses ' Me.TxtLosses.Location = New System.Drawing.Point(112, 80) Me.TxtLosses.Name = "TxtLosses" Me.TxtLosses.ReadOnly = True Me.TxtLosses.Size = New System.Drawing.Size(120, 22) Me.TxtLosses.TabIndex = 6 Me.TxtLosses.Text = "0" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(24, 80) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(72, 18) Me.Label3.TabIndex = 5 Me.Label3.Text = "Losses" ' 'BtnReset ' Me.BtnReset.Location = New System.Drawing.Point(24, 120) Me.BtnReset.Name = "BtnReset" Me.BtnReset.Size = New System.Drawing.Size(86, 37) Me.BtnReset.TabIndex = 7 Me.BtnReset.Text = "Reset" ' 'BtnQuit ' Me.BtnQuit.Location = New System.Drawing.Point(136, 120) Me.BtnQuit.Name = "BtnQuit" Me.BtnQuit.Size = New System.Drawing.Size(87, 37) Me.BtnQuit.TabIndex = 8 Me.BtnQuit.Text = "Quit" ' 'GroupBox1 ' Me.GroupBox1.Controls.Add(Me.Label2) Me.GroupBox1.Controls.Add(Me.Label3) Me.GroupBox1.Controls.Add(Me.TxtLosses) Me.GroupBox1.Controls.Add(Me.TxtWins) Me.GroupBox1.Controls.Add(Me.BtnReset) Me.GroupBox1.Controls.Add(Me.BtnQuit) Me.GroupBox1.Location = New System.Drawing.Point(24, 344) Me.GroupBox1.Name = "GroupBox1" Me.GroupBox1.Size = New System.Drawing.Size(272, 184) Me.GroupBox1.TabIndex = 9 Me.GroupBox1.TabStop = False Me.GroupBox1.Text = "Summary" ' 'PicDice1 ' Me.PicDice1.Image = CType(resources.GetObject("PicDice1.Image"), System.Drawing.Image) Me.PicDice1.Location = New System.Drawing.Point(16, 144) Me.PicDice1.Name = "PicDice1" Me.PicDice1.Size = New System.Drawing.Size(56, 40) Me.PicDice1.TabIndex = 10 Me.PicDice1.TabStop = False ' 'PicDice2 ' Me.PicDice2.Image = CType(resources.GetObject("PicDice2.Image"), System.Drawing.Image) Me.PicDice2.Location = New System.Drawing.Point(80, 144) Me.PicDice2.Name = "PicDice2" Me.PicDice2.Size = New System.Drawing.Size(56, 40) Me.PicDice2.TabIndex = 11 Me.PicDice2.TabStop = False ' 'BtnContinue ' Me.BtnContinue.Location = New System.Drawing.Point(24, 216) Me.BtnContinue.Name = "BtnContinue" Me.BtnContinue.Size = New System.Drawing.Size(105, 28) Me.BtnContinue.TabIndex = 12 Me.BtnContinue.Text = "Continue" Me.BtnContinue.Visible = False ' 'Label4 ' Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Underline), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label4.Location = New System.Drawing.Point(160, 128) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(64, 24) Me.Label4.TabIndex = 13 Me.Label4.Text = "Total" ' 'TxtTotal ' Me.TxtTotal.Location = New System.Drawing.Point(152, 168) Me.TxtTotal.Name = "TxtTotal" Me.TxtTotal.ReadOnly = True Me.TxtTotal.Size = New System.Drawing.Size(80, 22) Me.TxtTotal.TabIndex = 14 Me.TxtTotal.Text = "" ' 'TxtPoint ' Me.TxtPoint.Location = New System.Drawing.Point(248, 168) Me.TxtPoint.Name = "TxtPoint" Me.TxtPoint.ReadOnly = True Me.TxtPoint.Size = New System.Drawing.Size(80, 22) Me.TxtPoint.TabIndex = 16 Me.TxtPoint.Text = "" Me.TxtPoint.Visible = False ' 'Label5 ' Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Underline), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label5.Location = New System.Drawing.Point(256, 128) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(64, 24) Me.Label5.TabIndex = 15 Me.Label5.Text = "Point" Me.Label5.Visible = False ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15) Me.ClientSize = New System.Drawing.Size(632, 552) Me.Controls.Add(Me.TxtPoint) Me.Controls.Add(Me.Label5) Me.Controls.Add(Me.TxtTotal) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.BtnContinue) Me.Controls.Add(Me.PicDice2) Me.Controls.Add(Me.PicDice1) Me.Controls.Add(Me.GroupBox1) Me.Controls.Add(Me.LstResults) Me.Controls.Add(Me.BtnPlay) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.GroupBox1.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region Private Function diceRoll() As Integer Dim rand As Integer ' generates random value between 0 and 5, then adds 1 rand = Convert.ToInt32(5 * Rnd() + 1) Return rand End Function Private Sub displayDice1(ByVal roll As Integer) ' display dice icons Dim MyImage As Bitmap Dim diceImageFilename As String Select Case roll Case 1 diceImageFilename = "DieOne.gif" Case 2 diceImageFilename = "DieTwo.gif" Case 3 diceImageFilename = "DieThree.gif" Case 4 diceImageFilename = "DieFour.gif" Case 5 diceImageFilename = "DieFive.gif" Case 6 diceImageFilename = "DieSix.gif" End Select MyImage = New Bitmap(diceImageFilename) PicDice1.Image = CType(MyImage, Image) End Sub Private Sub displayDice2(ByVal roll As Integer) ' display dice icons Dim MyImage As Bitmap Dim diceImageFilename As String Select Case roll Case 1 diceImageFilename = "DieOne.gif" Case 2 diceImageFilename = "DieTwo.gif" Case 3 diceImageFilename = "DieThree.gif" Case 4 diceImageFilename = "DieFour.gif" Case 5 diceImageFilename = "DieFive.gif" Case 6 diceImageFilename = "DieSix.gif" End Select MyImage = New Bitmap(diceImageFilename) PicDice2.Image = CType(MyImage, Image) End Sub ' roll dice, display them in picture boxes, and in listbox, and return total Private Function rollNDisplayDice() As Integer Dim dice1 As Integer Dim dice2 As Integer ' roll dice dice1 = diceRoll() dice2 = diceRoll() ' display dice displayDice1(dice1) displayDice2(dice2) ' determine total, and display Dim total As Integer total = dice1 + dice2 TxtTotal.Text = total.ToString("n0") LstResults.Items.Add("Roll: " & total & " (" & dice1 & " and " & dice2 & ")") Return total End Function Private Sub BtnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPlay.Click Dim point As Integer LstResults.Items.Clear() ' roll dice and diplay total Dim total As Integer total = rollNDisplayDice() ' determine if first roll wins, loses or is still pending Select Case total Case 7, 11 MsgBox("You win!") Dim wins As Integer wins = Convert.ToInt32(TxtWins.Text) wins = wins + 1 TxtWins.Text = wins.ToString("") TxtPoint.Visible = False Label5.Visible = False Case 2, 3, 12 MsgBox("You lose, sucker!") Dim losses As Integer losses = Convert.ToInt32(TxtLosses.Text) losses = losses + 1 TxtLosses.Text = losses.ToString("") TxtPoint.Visible = False Label5.Visible = False Case Else point = total TxtPoint.Text = point.ToString("n0") TxtPoint.Visible = True Label5.Visible = True BtnContinue.Visible = True BtnPlay.Visible = False End Select End Sub Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click Me.Close() End Sub Private Sub BtnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReset.Click TxtWins.Text = "0" TxtLosses.Text = "0" LstResults.Items.Clear() End Sub Private Sub BtnContinue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnContinue.Click Dim dice1 As Integer Dim dice2 As Integer Dim total As Integer Dim point As Integer point = Convert.ToInt32(TxtPoint.Text) total = rollNDisplayDice() 'TxtTotal.Text = total.ToString("n0") If total = 7 Then MsgBox("You lose, sucker!") Dim losses As Integer losses = Convert.ToInt32(TxtLosses.Text) losses = losses + 1 TxtLosses.Text = losses.ToString("") BtnContinue.Visible = False BtnPlay.Visible = True TxtPoint.Visible = False Label5.Visible = False ElseIf total = point Then MsgBox("You win!") Dim wins As Integer wins = Convert.ToInt32(TxtWins.Text) wins = wins + 1 TxtWins.Text = wins.ToString("") BtnContinue.Visible = False BtnPlay.Visible = True End If End Sub End Class